package com.example.carrierapp.ui.main.waybill;

import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v4.app.Fragment;
import android.support.v4.view.ViewPager;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.RadioButton;
import android.widget.RadioGroup;
import android.widget.RelativeLayout;

import com.example.carrierapp.base.BaseFragment;
import com.example.carrierapp.ui.adapter.WaybillMainAdapter;
import com.example.carrierapp.ui.view.PagerSlidingTabStrips;
import com.example.carrierapp.util.EditTextUtils;
import com.example.lb.fingerdemo.R;

import butterknife.BindView;
import butterknife.ButterKnife;

public class WaybillFragment extends BaseFragment {
    @BindView(R.id.vp_waybill_container)
    ViewPager mViewPager;
    @BindView(R.id.toolbar)
    RelativeLayout toolbar;
    @BindView(R.id.toolbar_radio_group)
    RadioGroup toolbarRadGro;
    @BindView(R.id.toolbar_radio_button_left)
    RadioButton toolbarRadBtnL;
    @BindView(R.id.toolbar_radio_button_right)
    RadioButton toolbarRadBtnR;

    public static Fragment newInstance() {
        Bundle args = new Bundle();
        WaybillFragment waybillFragment = new WaybillFragment();
        waybillFragment.setArguments(args);
        return waybillFragment;
    }

    @Override
    protected int getLayout() {
        return R.layout.fragment_waybill;
    }

    @Nullable
    @Override
    public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
        return super.onCreateView(inflater, container, savedInstanceState);
    }

    @Override
    public void onPause() {
        super.onPause();
        EditTextUtils.hideSoftKeyboard(getActivity());
    }
    private void initTitle() {
        toolbarRadBtnL.setText("运输中");
        toolbarRadBtnR.setText("已送达");
    }
    @Override
    public void initView() {
        super.initView();
        ButterKnife.bind(this,mRootView);
        initTitle();
        WaybillMainAdapter mAdapter=new WaybillMainAdapter(getChildFragmentManager(),getResources().getStringArray(R.array.title_waybill));
        mViewPager.setAdapter(mAdapter);
        mViewPager.setCurrentItem(0);
    }

    @Override
    public void initEvent() {
        super.initEvent();
        toolbarRadGro.setOnCheckedChangeListener((group, checkedId) -> {
            switch (checkedId) {
                case R.id.toolbar_radio_button_left:
                    mViewPager.setCurrentItem(0);
                    break;
                case R.id.toolbar_radio_button_right:
                    mViewPager.setCurrentItem(1);
                    break;
                default:
                    break;
            }

        });
        mViewPager.addOnPageChangeListener(new ViewPager.OnPageChangeListener() {
            @Override
            public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) {

            }

            @Override
            public void onPageSelected(int position) {
                switch (position) {
                    case 0:
                        toolbarRadGro.check(R.id.toolbar_radio_button_left);
                        break;
                    case 1:
                        toolbarRadGro.check(R.id.toolbar_radio_button_right);
                        break;
                    default:
                        break;

                }
            }

            @Override
            public void onPageScrollStateChanged(int state) {

            }
        });
    }
}
